<?php

namespace App\Model\Task;

use App\Dao\Task\TaskDao;
use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;

/**
 * @property integer $id
 * @property integer $create_time
 * @property integer $update_time
 * @property integer $delete_time
 * @property integer $user_id
 * @property integer $task_id
 */
class TaskLog extends Model
{
    use SoftDeletes;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'task_log';

    protected $appends = [
        'create_time_format',
        'types_format',
    ];

    protected $fillable = [
        'create_time',
        'update_time',
        'delete_time',
        'user_id',
        'task_id',
        'types',
    ];

    public function getCreateTimeFormatAttribute()
    {
        return $this->checkAttributes('create_time', function ($value) {
            return date('Y-m-d H:i:s', $value);
        });
    }

    public function getTypesFormatAttribute()
    {
        return $this->checkAttributes('types', function ($value) {
            return [
                    'top' => '置顶',
                    'refresh' => '刷新',
                ][$value] ?? '';
        });
    }

    public function Task()
    {
        return $this->hasOne(Task::class, 'id', 'task_id');
    }


}
